home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / utils sync / JetSync 1.0 / jetsync-1.0.exe / jetsync-1.0 / setup < prev   
Encoding:
Text File  |  1999-10-13  |  12.0 KB  |  483 lines

  1. #! /bin/sh
  2. # 1 2 3 \
  3. exec `which wish | cut -d\  -f1` $0
  4.  
  5. set LIBDIR libjetsync
  6. set CONDUITDIR Conduits
  7. set APPNAME JetSync
  8. set DEBUG 0
  9. set CLEAN 0
  10. set HOME $env(HOME)
  11. set JETHOME $HOME/.jetsync
  12. set USERNAME ""
  13. set PASSWORD ""
  14. set DATAPATH $HOME
  15. set seed [expr [clock seconds] % 10]
  16.  
  17. proc random { max} {
  18.   global seed
  19.   
  20.   incr seed
  21.   set secs [clock seconds]
  22.   set i [expr [expr $secs * $seed] % $max + 1]
  23.   if { ![regexp {0[8-9]} $secs] } {
  24.     set seed [expr $secs % 10]
  25.   } else {
  26.     set seed [expr [clock format [clock seconds] -format %S]]
  27.   }
  28.   return $i
  29. }
  30.  
  31.  
  32. proc progress { pos } {
  33.   .f2.c create rect 45 11 [expr 45 + [expr $pos * 2]] 21 -fill #1a5814
  34.   .f2.l configure -text "${pos}%"
  35.   update
  36. }
  37.  
  38. proc doJobInstall { flag } {
  39.   global HOME JETHOME USERPATH USERNAME APPNAME DATAPATH PASSWORD
  40.  
  41.   wm title . "Installing $APPNAME..."
  42.  
  43.   if {![file isdirectory $DATAPATH]} {
  44.     .f1.l configure -text "Directory \"$DATAPATH\" does not exist!"
  45.     update
  46.     return
  47.   }
  48.  
  49.   if {![string compare "" $USERNAME]} {
  50.     .f1.l configure -text "Please specify a valid user name!"
  51.     update
  52.     return
  53.   }
  54.  
  55.   if {![string compare "" $PASSWORD]} {
  56.     .f1.l configure -text "Please specify a password for $USERNAME!"
  57.     update
  58.     return
  59.   }
  60.  
  61.   if {![string compare "" $JETHOME]} {
  62.     .f1.l configure -text "Please specify a valid JetSync home directory!"
  63.     update
  64.     return
  65.   }
  66.  
  67.   set str [split $JETHOME /]
  68.   set str [lrange $str 1 [expr [llength $str] - 2]]
  69.   set USERPATH [join "/$str" "/"]
  70.  
  71.   if {![file isdirectory $USERPATH]} {
  72.     .f1.l configure -text "Please specify a valid JetSync home directory!"
  73.     update
  74.     return
  75.   }
  76.  
  77.   destroy .f2 .f3
  78.   wm geometry . 449x241
  79.   frame .f2
  80.   pack .f2
  81.  
  82.   canvas .f2.c -relief flat -width 250 -height 30 -bd 1
  83.   label .f2.l -text "0%"
  84.   pack .f2.c .f2.l -side left
  85.   .f2.c create rect 45 11 245 21 -fill white
  86.   update
  87.  
  88. #PHASE 1
  89.  
  90.   set perc 0
  91.   progress $perc
  92.  
  93. # test directory existence
  94.   if {![file isdirectory $JETHOME]} {
  95.     after 300
  96.     .f1.l configure -text "Creating directory JetSync directory..."
  97.     update
  98.     file mkdir $JETHOME
  99.     catch { file attributes $JETHOME -permissions 0755 }
  100. # file attributes does not work with Tcl/Tk <= 7.6 this line should be
  101. # commented and the permissions should be set manually.
  102.   }
  103.  
  104.   set perc 5
  105.   progress $perc
  106.  
  107.   if { $flag } {
  108.     set dirlist "bin conf default images"
  109.   } else {
  110.     set dirlist bin
  111.   }
  112.   foreach i $dirlist {
  113.     incr perc 5
  114.     progress $perc
  115.     if {![file isdirectory $JETHOME/$i]} {
  116.       after 300
  117.       .f1.l configure -text "Creating directory $i..."
  118.       update
  119.       file mkdir $JETHOME/$i
  120.       catch { file attributes $JETHOME/$i -permissions 0755 }
  121. # file attributes does not work with Tcl/Tk <= 7.6 this line should be
  122. # commented and the permissions should be set manually.
  123.     }
  124.   }
  125.  
  126. #PHASE 2
  127.  
  128.   set perc 25
  129.   progress $perc
  130.  
  131.   after 300
  132.   .f1.l configure -text "Installing jetsync..."
  133.   update
  134.   exec install -m 0755 setup.dir/help.tcl  $JETHOME/bin/help.tcl
  135.  
  136.   exec install -m 0755 src/jetsync $JETHOME/bin/jetsync
  137.   exec install -m 0755 src/jetsync.exe $JETHOME/bin/jetsync.exe
  138.  
  139. # install bin directory
  140.   foreach {i} {addr memo todo} {
  141.     incr perc 6
  142.     progress $perc
  143.     after 300
  144.     .f1.l configure -text "Installing jet$i..."
  145.     update
  146.     exec install -m 0755 src/$i/jet$i $JETHOME/bin/jet$i
  147.     exec install -m 0755 src/$i/jet$i.exe $JETHOME/bin/jet$i.exe
  148.  
  149.     # copy default initial data files
  150.     file copy -force setup.dir/default/${i}s $DATAPATH/${i}s
  151.   }
  152.  
  153. # copy iCal file
  154.   file copy -force setup.dir/default/i.cal $DATAPATH/i.cal
  155.  
  156. #PHASE 3 - only if option is "Install all"
  157.  
  158.   if { $flag } {
  159.     set perc 50
  160.     progress $perc
  161.  
  162.     after 300
  163.     .f1.l configure -text "Configuring JetSync directory..."
  164.     update
  165.  
  166. # install conf directory
  167.     exec install -m 0755 setup.dir/button.def $JETHOME/conf/button.def
  168.     incr perc 5
  169.     progress $perc
  170.  
  171.     set fp [open $JETHOME/conf/jetusers w]
  172.     puts $fp "$USERNAME:$PASSWORD:[random 999999999]"
  173.     close $fp
  174.     catch { file attributes $JETHOME/conf/jetusers -permissions 0755 }
  175. # file attributes does not work with Tcl/Tk <= 7.6 this line should be
  176. # commented and the permissions should be set manually.
  177.     incr perc 5
  178.     progress $perc
  179.  
  180.     set fp [open $JETHOME/conf/prefs w]
  181.     puts $fp "PCID:0"
  182.     puts $fp "USER:$USERNAME"
  183.     puts $fp "MODEM:/dev/cua0"
  184.     puts $fp "MODEMSPEED:14400"
  185.     puts $fp "MODEMTYPE:Standard"
  186.     puts $fp "MODEMSTR:AT&FX4"
  187.     puts $fp "LOCAL:/dev/cua0"
  188.     puts $fp "LOCALSPEED:19200"
  189.     puts $fp "DAEMON:2:-1"
  190.     close $fp
  191.     catch { file attributes $JETHOME/conf/prefs -permissions 0755 }
  192. # file attributes does not work with Tcl/Tk <= 7.6 this line should be
  193. # commented and the permissions should be set manually.
  194.     incr perc 5
  195.     progress $perc
  196.  
  197. # install default directory
  198.     foreach {i} [exec ls setup.dir/default/] {
  199.       exec install -m 0755 setup.dir/default/$i $JETHOME/default
  200.     }
  201.     file mkdir $JETHOME/$USERNAME
  202.     file mkdir $JETHOME/$USERNAME/conf
  203.     exec install -m 0755 setup.dir/default/color.def \
  204.       $JETHOME/$USERNAME/conf/color.def
  205.     exec install -m 0755 setup.dir/default/conduits.def \
  206.       $JETHOME/$USERNAME/conf/conduits.def
  207.     exec install -m 0755 setup.dir/default/conduits.lst \
  208.       $JETHOME/conf/conduits.lst
  209.  
  210.     set fp [open $JETHOME/$USERNAME/conf/prefs w]
  211.     puts $fp "MODNUM:0"
  212.     close $fp
  213.  
  214. # create an empty mapfile
  215.     set fp [open "$JETHOME/$USERNAME/conf/ical.map" w]
  216.     close $fp
  217.  
  218. # install application-driven data
  219.     foreach {i} {jetmemo jetaddr jettodo jetdate} {
  220.       set fp [open $JETHOME/$USERNAME/conf/$i.dat w]
  221.       puts $fp "$DATAPATH"
  222.       close $fp
  223.       file copy -force setup.dir/default/$i.cat \
  224.            $JETHOME/$USERNAME/conf/$i.cat
  225.     }
  226. # empty mail config file
  227.     set fp [open "$JETHOME/$USERNAME/conf/jetmail.dat" w]
  228.     close $fp
  229.  
  230.     incr perc 5
  231.     progress $perc
  232. # install images directory
  233.     foreach {i} [exec ls setup.dir/images/] {
  234.       exec install -m 0755 setup.dir/images/$i $JETHOME/images
  235.     }
  236.  
  237.     # create empty log file
  238.     set fp [open $JETHOME/$USERNAME/hotsync.log w]
  239.     close $fp
  240.  
  241.     incr perc 5
  242.     progress $perc
  243.   }
  244.  
  245. #PHASE 4
  246.   set perc 75
  247.   progress $perc
  248.  
  249. # setup apps
  250.   foreach {i} {jetsync jetmemo jetaddr jettodo} {
  251.     incr perc 6
  252.     progress $perc
  253.     after 300
  254.     .f1.l configure -text "Initializing $i..."
  255.     update
  256.     exec cat $JETHOME/bin/$i | sed s%@@JETHOME@@%$JETHOME%g \
  257.     > $JETHOME/bin/$i.tmp
  258.     file rename -force $JETHOME/bin/$i.tmp $JETHOME/bin/$i
  259.     catch { file attributes $JETHOME/bin/$i -permissions 0755 }
  260. # file attributes does not work with Tcl/Tk <= 7.6 this line should be
  261. # commented and the permissions should be set manually.
  262.   }
  263.  
  264.   .f1.l configure \
  265.   -text "Installation of JetSync was successfully completed!"
  266.   progress 100
  267.  
  268.   frame .f3
  269.   pack .f3
  270.  
  271.   button .f3.quit -text "Quit" -command "destroy ."
  272.   pack .f3.quit
  273.  
  274.   tkwait win .f1
  275. }
  276.  
  277.  
  278. proc doInstall {} {
  279.   global HOME USERNAME JETHOME APPNAME
  280.  
  281.   wm title . "Configure $APPNAME..."
  282.  
  283.   .f1.l configure -text "Installing project..."
  284.  
  285.   catch {destroy .f2 .f3}
  286.   wm geometry . 535x520
  287.   update
  288.  
  289.  
  290.   frame .f2
  291.   frame .f3
  292.   pack .f2 .f3 -pady 15
  293.  
  294.   label .f2.l1 -text "Where do you want to install JetSync?" \
  295.   -anchor w
  296.   entry .f2.e1 -textvariable JETHOME -width 100
  297.  
  298.   label .f2.l2 -text "Please type the name of the first user:" -anchor w
  299.   entry .f2.e2 -textvariable USERNAME -width 100
  300.  
  301.   label .f2.l -text "Please type a password for the user:" -anchor w
  302.   entry .f2.e -textvariable PASSWORD -width 100 -show "*"
  303.  
  304.   label .f2.l3 -text "Please enter a valid data directory path for that user:" \
  305.   -anchor w
  306.   entry .f2.e3 -textvariable DATAPATH -width 100
  307.  
  308.   button .f3.b1 -text "Install all" -command "doJobInstall 1"
  309.   button .f3.b2 -text "Install binaries only" -command "doJobInstall 0"
  310.   button .f3.b3 -text "Quit" -command exit
  311.  
  312.   pack .f2.l1 .f2.e1 -pady 5 -anchor w
  313.   pack .f2.l2 .f2.e2 -pady 5 -anchor w
  314.   pack .f2.l .f2.e -pady 5 -anchor w
  315.   pack .f2.l3 .f2.e3 -pady 5 -anchor w
  316.  
  317.   pack .f3.b1 .f3.b2 .f3.b3 -side left -padx 10
  318. }
  319.  
  320. proc doMake {} {
  321.   global LIBDIR CONDUITDIR APPNAME DEBUG CLEAN
  322.  
  323.   .f1.l configure -text "Making project..."
  324.   destroy .f2 .f3
  325.   wm geometry . 595x327
  326.   update
  327.  
  328.   frame .f2
  329.   pack .f2
  330.   text .f2.t -yscrollcommand ".f2.scroll set" -width 80 -height 25
  331.   scrollbar .f2.scroll -command ".f2.t yview"
  332.   pack .f2.t .f2.scroll -side left -fill y
  333.  
  334.   set DEFFLAGS "-Wall -g -O2 -I$LIBDIR -I$CONDUITDIR -I."
  335.   set FLAGS ""
  336.  
  337. # make the thing
  338.   if { $CLEAN } {
  339.     .f1.l configure -text "Cleaning distribution..."
  340.     update
  341.     exec make clean >& /dev/null
  342.   }
  343.   if { $DEBUG } {
  344.     set child_pid [exec make debug CFLAGS=$DEFFLAGS\ $FLAGS stop >& /tmp/err &]
  345.   } else {
  346.     set child_pid [exec make all CFLAGS=$DEFFLAGS\ $FLAGS stop >& /tmp/err &]
  347.   }
  348.  
  349.   set err 0
  350.   .f1.l configure -text "Making project..."
  351.   while { 1 } {
  352.     set fp [open "/tmp/err" r]
  353.     if { [string compare "" [.f2.t search -regexp \
  354.     {\*\*\* \[[a-zA-Z0-9._\-]*.o\] Error} 1.0 end]] } \
  355.     { set err 1; break }
  356.     if { [string compare "" [.f2.t search -exact "__EOF__" 1.0 end]] } break
  357.    
  358.     set text ""
  359.     .f2.t delete 1.0 end
  360.     while {[gets $fp line] >= 0 } {
  361.       .f2.t insert end "$line\n"
  362.     }
  363.     .f2.t yview moveto 1.0
  364.     update
  365.     close $fp
  366.     exec sleep 1
  367.     }
  368.   if { ! $err } {
  369.     tk_messageBox -type ok -title "Success" \
  370.       -message "Building was successfully completed!"
  371.   } else {
  372.     catch { exec kill -TERM $child_pid >& /dev/null }
  373.     tk_messageBox -type ok -title "Error" -message "Building was not successful!"
  374.     exec /bin/rm -f /tmp/err
  375.     exit
  376.   }
  377.   exec /bin/rm -f /tmp/err
  378.   doInstall
  379. }
  380.  
  381. proc doWork {} {
  382.   global autoconf configure make
  383.   global LIBDIR CONDUITDIR APPNAME DEBUG CLEAN
  384.  
  385.   wm title . "Building $APPNAME..."
  386.   wm geometry . 295x147
  387.  
  388.   frame .f1
  389.   frame .f2
  390.   frame .f3
  391.   pack .f1 .f2 .f3 -pady 10
  392.  
  393.   label .f1.l -text "" -justify center -fg Blue
  394.   pack .f1.l -pady 15
  395.   update
  396.  
  397.   if { $autoconf } {
  398.     .f1.l configure -text "Creating configure..."
  399.     update
  400.     exec /bin/rm -f config.*
  401.     catch {exec autoconf} var
  402.     if {[string compare "" $var]} {
  403.       tk_messageBox -type ok -title "Error" \
  404.       -message "Error while running 'autoconf'!"
  405.       exit
  406.     }
  407.   }
  408.  
  409.   if { $configure } {
  410.     .f1.l configure -text "Configuring $APPNAME..."
  411.     update
  412.     exec /bin/rm -f config.cache
  413.     catch {exec ./configure} var
  414.  
  415.     if { [regexp {\*\*\*} $var] } {
  416.       tk_messageBox -type ok -title "Error" \
  417.       -message "Error while running 'configure'!"
  418.       exit
  419.     }
  420.   }
  421.  
  422.   catch {exec whereis -b make} res
  423.   if {![string compare "" [lindex $res 1]]} {
  424.     tk_messageBox -type ok -icon error -title "Fatal error" \
  425.     -message "There is no 'make' installed in your system. Cannot proceed!"
  426.     exit
  427.   }
  428.  
  429.   if { $make } {
  430.     wm geometry . 300x330
  431.     .f1.l configure -text "Make project options..."
  432.     update
  433.  
  434. # test for flags
  435.     checkbutton .f2.c1 -text "Clean distribution before making" -variable CLEAN
  436.  
  437. # test for make options (debug, clean...)
  438.     checkbutton .f2.c2 -text "Make with debug option" -variable DEBUG
  439.  
  440.     pack .f2.c1 .f2.c2 -pady 15 -anchor w
  441.  
  442.     button .f3.b1 -text "Make" -command doMake
  443.     button .f3.b2 -text "Quit" -command exit
  444.  
  445.     pack .f3.b1 .f3.b2 -side left -padx 20
  446.   } else doInstall
  447. }
  448.  
  449. wm title . "$APPNAME Setup"
  450. wm geometry . 268x285+200+200
  451. frame .fA
  452. frame .f0
  453. frame .f1
  454. frame .f2
  455. pack .fA -anchor w -pady 5 -padx 5
  456. pack .f0 .f1 .f2 -pady 10
  457.  
  458. image create photo setupimg -file setup.dir/setup.gif
  459. label .fA.l0 -image setupimg -anchor w
  460. pack .fA.l0 -anchor w
  461.  
  462. label .f0.l -text "Please choose the following setup options:"
  463. pack .f0.l
  464.  
  465. set autoconf 0
  466. checkbutton .f1.c1 -text "Run autoconf" -variable autoconf -anchor w
  467.  
  468. catch {exec whereis -b autoconf} res
  469. if {![string compare "" [lindex $res 1]]} {
  470.   .f1.c1 configure -state disabled
  471. }
  472.  
  473. set configure 1
  474. checkbutton .f1.c2 -text "Run configure" -variable configure -anchor w
  475. set make 1
  476. checkbutton .f1.c3 -text "Perform make" -variable make -anchor w
  477.  
  478. pack .f1.c1 .f1.c2 .f1.c3 -pady 5 -anchor w
  479.  
  480. button .f2.b1 -text "Build $APPNAME" -command "destroy .f0 .f1 .f2; doWork"
  481. button .f2.b2 -text "Cancel setup" -command "exit"
  482. pack .f2.b1 .f2.b2 -side left -padx 10
  483.